import 'package:flutter/cupertino.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';

class ZtRefreshFooter extends StatefulWidget {
  const ZtRefreshFooter({Key? key}) : super(key: key);

  @override
  State<ZtRefreshFooter> createState() => _ZtRefreshFooterState();
}

class _ZtRefreshFooterState extends State<ZtRefreshFooter>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return buildBody();
  }

  Widget buildBody() {
    TextStyle style = TextStyle(fontSize: ZtScreenAdaper.sp(18));
    return CustomFooter(
      builder: (BuildContext context, LoadStatus? status) {
        Widget body;
        if (status == LoadStatus.idle) {
          body = const Text("Pull up to get latest messages");
        } else if (status == LoadStatus.loading) {
          body = const SizedBox(child: const CupertinoActivityIndicator());
        } else if (status == LoadStatus.failed) {
          body = Text(
            "Load failed, please try again",
            style: style,
          );
        } else if (status == LoadStatus.canLoading) {
          body = const CupertinoActivityIndicator(
            animating: false,
          );
        } else {
          body = const SizedBox();
        }
        return SizedBox(
          height: ZtScreenAdaper.height(20),
          child: Center(child: body),
        );
      },
    );
  }
}
